package com.shaodongbo.facerecognition;

import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

public class MainActivity extends AppCompatActivity {
    private static final int GET_FACE_END = 1001;
    private Location location;
    private Handler handler;
    private MyImageView myImageView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        myImageView = findViewById(R.id.myImageView);
        handler = new Handler(new Handler.Callback() {
            @Override
            public boolean handleMessage(Message msg) {
                if (msg.what == GET_FACE_END){
                    myImageView.shouFace(location);
                }
                return false;
            }
        });

        findViewById(R.id.btn_face).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                final String huaPath = "/mnt/shared/Image/hua.jpg";
                String fourPath = "/mnt/shared/Image/four.jpg";
                byte[] imgByte = Base64Util.image2byte(huaPath);
                final String base64 = Base64Util.encode(imgByte);
                Log.e("FACE", "base64 : " + base64);
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        location = FaceDetect.detect(base64);
                        handler.sendEmptyMessage(GET_FACE_END);
                    }
                }).start();
            }
        });
    }

    private String getBase64Str(String s) {
        return null;
    }
}
